package fw.qaz.asmx.reader.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class VPAdapter extends FragmentStatePagerAdapter
{
    private List<Fragment> fragments;
    private List<String> titles;

    public VPAdapter(FragmentManager fm)
    {
        super(fm);
        fragments = new ArrayList<>();
        titles = new ArrayList<>();
    }

    public void addFragment(Fragment fragment,String title)
    {
        fragments.add(fragment);
        titles.add(title);
        notifyDataSetChanged();
    }

    @Override public Fragment getItem(int position)
    {
        return fragments.get(position);
    }

    @Override public int getCount()
    {
        return fragments.size();
    }

    @Override public CharSequence getPageTitle(int position)
    {
        return titles.get(position);
    }
}
